package com.knife.blog.logic.impl;

import java.util.Collection;

import com.knife.blog.domain.BlogCircleDir;
import com.knife.blog.logic.BlogCircleDirService;
import com.knife.web.tools.DbPageList;
import com.knife.web.tools.IPageList;

public class BlogCircleDirServiceImpl extends DAOSupportService implements BlogCircleDirService {

    private static BlogCircleDirServiceImpl blogCircleDirService = new BlogCircleDirServiceImpl();

    public static BlogCircleDirServiceImpl getInstance() {
        return blogCircleDirService;
    }

    public BlogCircleDir getBlogCircleDir(String cid) {
        // TODO 自动生成方法存根
        return (BlogCircleDir) this.dao.get(BlogCircleDir.class, cid);
    }

    public BlogCircleDir getFatherCircleDir(String cid) {
        BlogCircleDir dir = getBlogCircleDir(cid);
        BlogCircleDir fatherDir = getBlogCircleDir(dir.getParentsn());
        return fatherDir;
    }

    public boolean addBlogCircleDir(BlogCircleDir circleDir) {
        // TODO 自动生成方法存根
        return false;
    }

    public boolean delBlogCircleDir(String cid) {
        // TODO 自动生成方法存根
        return this.dao.del(getBlogCircleDir(cid));
    }

    public boolean updateBlogCircleDir(BlogCircleDir circle) {
        // TODO 自动生成方法存根
        return this.dao.update(circle);
    }

    public int batchDelBlogCircleDir(String[] cid) {
        // TODO 自动生成方法存根
        int ret = 0;
        for (String str : cid) {
            if (delBlogCircleDir(str)) {
                ret++;
            }
        }
        return ret;
    }

    public IPageList queryTopCircleDir(int currentPage, int pageSize) {
        // TODO 自动生成方法存根
        String scope = "parentsn='0'";
        return queryBlogCircleDir(scope, null, currentPage, pageSize);
    }

    public IPageList queryChildCircleDir(BlogCircleDir topCircleDir, int currentPage, int pageSize) {
        // TODO 自动生成方法存根
        String scope = "parentsn=?";
        java.util.Collection paras = new java.util.ArrayList();
        paras.add(topCircleDir.getCid());
        return queryBlogCircleDir(scope, paras, currentPage, pageSize);
    }

    public IPageList queryChildCircleDir(String fatherDir, int currentPage, int pageSize) {
        // TODO 自动生成方法存根
        BlogCircleDir dir = getBlogCircleDir(fatherDir);
        return queryChildCircleDir(dir, currentPage, pageSize);
    }

    public IPageList queryBlogCircleDir() {
        String scope = "1=1";
        return queryBlogCircleDir(scope, null, 0, -1);
    }

    public IPageList queryBlogCircleDir(String scope, Collection paras, int currentPage, int pageSize) {
        DbPageList pList = new DbPageList(BlogCircleDir.class, scope, null);
        pList.doList(currentPage, pageSize);
        return pList;
    }
}
